home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9103.zip / TIMER1.C < prev   
Text File  |  1991-02-12  |  2KB  |  78 lines

  1. /**************************************************************
  2. * TIMER1.C - this program calculates the execution time of    *
  3. *   function testfunc().                                      *
  4. *                                                             *
  5. * To compile: "cl /Od /Fa /Gs timer1.c"                       *
  6. * RHS 9/30/90                                                                  *
  7. **************************************************************/
  8. #include<time.h>
  9. #include<process.h>
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12.  
  13. #define DEF_ITERATIONS   10000000L
  14. #define TRUE 1
  15. #define FALSE 0
  16.  
  17. int a, b = 3, c = 7;
  18.  
  19. int testfunc(int a, int b);
  20. void cdecl main(int argc, char **argv);
  21.  
  22. /**************************************************************
  23. * testfunc - the function whose execution time we are testing *
  24. **************************************************************/
  25. struct { int x, y; } pt ;
  26.  
  27. int testfunc(int dx, int dy)
  28.   /* Adjust the pt by (dx,dy) and return */
  29.   /* the quadrant of the point (x,y).    */
  30.   {
  31.     pt.x += dx;
  32.     pt.y += dy;
  33.     return( (pt.x & pt.y >= 0) ? 0 :
  34.             (pt.x & pt.y < 0)  ? 2 :
  35.             (pt.x < 0)         ? 1 : 3 );
  36.   }
  37.  
  38. /**************************************************************
  39. * main - calculates the execution time of the function        *
  40. * testfunc which appears above.                               *
  41. **************************************************************/
  42. void cdecl main(int argc, char **argv)
  43.     {
  44.     long start = 0L, end = 0L;
  45.     unsigned long iterations, setting =  DEF_ITERATIONS;
  46.     unsigned def = FALSE;
  47.     float test,empty,op;
  48.  
  49.     if(argc < 2)
  50.         def = TRUE;
  51.     else
  52.         {
  53.         if(!atol(argv[1]))
  54.             def = TRUE;
  55.         else
  56.             setting = atol(argv[1]);
  57.         }
  58.  
  59.     if(def)
  60.         printf("Testing with default iterations: %lu\n",setting);
  61.     else
  62.         printf("Testing with %lu iterations\n",setting);
  63.  
  64.     puts("Testing code...");
  65.     iterations = setting;
  66.     start = clock();
  67.     for( ; iterations; iterations--)
  68.         c = testfunc(a,b);
  69.     end = clock();
  70.     test = (float)(end-start);
  71.     test /= CLK_TCK;
  72.  
  73.     printf("Test end:\n");
  74.     printf(" Function test required: %04.2f seconds\n", test);
  75.     printf("   Test function took: %04.2f uSecs. per iteration\n",
  76.            test*(1E6/setting));
  77.     }
  78.